<!--
	Desc: 	围栏表的编辑界面
	Author: caochaofeng
	Date: 	2018-08-19 17:21:27
-->

<template>
  <el-dialog
    :title=" '修改ip'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="120px">
      <el-form-item label="IP" prop="ip">
        <el-input v-model="dataForm.ip" placeholder="112.74.131.151" ></el-input>
      </el-form-item>
      <el-form-item label="TCP端口" prop="port">
        <el-input v-model="dataForm.port" placeholder="6969"></el-input>
      </el-form-item>
      <el-form-item label="锁号" prop="lockDevID">
        <el-input v-model="dataForm.lockDevID" placeholder="lockDevID"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="changeIpSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import * as $http from '@/api/device'

  export default {
    data() {
      return {
        visible: false,

        dataForm: {
          lockDevID: '',
          ip: '112.74.131.151',
          port: '6969'
        },
        dataRule: {
          ip: [
            {required: true, message: 'IP不能为空', trigger: 'blur'}
          ],
          port: [
            {required: true, message: '端口不能为空', trigger: 'blur'}
          ],
          lockDevID: [
            {required: true, message: '锁号不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init(code) {

        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.dataForm.lockDevID = code
        })
      },
      // 表单提交
      changeIpSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = this.dataForm
           $http.changeIp(params).then((data) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '修改ip操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
